package com.nnfe.fyd.feature.inquiry;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.nnfe.fyd.R;
import com.nnfe.fyd.base.MyBaseAdapter;
import com.nnfe.fyd.bean.myinquirt.InquirtBean;
import com.nnfe.fyd.feature.inquiryreport.InquiryReportAcivity;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * ----------------------------------
 * Created by xyd on 2017/4/20.
 * <p/>
 * 描  述：
 * <p/>
 * 修订历史:
 * ----------------------------------
 */

public class InquiryAdapter_list extends MyBaseAdapter {

    public InquiryAdapter_list(Context mContext) {
        super(mContext);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {

            convertView = View.inflate(mContext, R.layout.layout_inquiry, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }


        final InquirtBean.Inquirt bean = (InquirtBean.Inquirt) getItem(position);
        viewHolder.danhao.setText("单号：" + bean.id);

        // 自动寻价         -- 》  显示小区名称,显示面积
        // 手动询价
        //           有房本 -- 》  显示小区名称，不显示面积
        //           无房本 -- 》  显示小区名称，显示面积，详情里房屋地址有则显示，没有就隐藏
        // 列表页都不显示房屋地址


        // 有房本
        if ("1".equalsIgnoreCase(bean.isOwnership)) {
            if (!TextUtils.isEmpty(bean.areaName)) {
                viewHolder.zhuzhi.setText("小区名称：" + bean.areaName);
            }
            viewHolder.mianji.setVisibility(View.INVISIBLE);
        } else {
            if (!TextUtils.isEmpty(bean.areaName)) {
                viewHolder.zhuzhi.setText("小区名称：" + bean.areaName);
            }
            viewHolder.mianji.setText("建筑面积：" + bean.housingArea + "平米");
            viewHolder.mianji.setVisibility(View.VISIBLE);
        }


        // 通过审核则有报单金额区间
        // 已报过单，则loanAmout 有报单记录
        if (TextUtils.isEmpty(bean.loanLimitMax) || Double.parseDouble(bean.loanLimitMax) == 0) {
            viewHolder.baodan.setEnabled(false);
            viewHolder.baodan.setText("报单");
        } else {
            if (TextUtils.isEmpty(bean.loanAmount)) {
                viewHolder.baodan.setEnabled(true);
                viewHolder.baodan.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        InquiryReportAcivity.lauch(mContext, bean.id, bean.loanLimitMax);
                    }
                });
                viewHolder.baodan.setText("报单");
            } else {
                viewHolder.baodan.setEnabled(false);
                viewHolder.baodan.setText("已报单");
            }
        }


        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyinquiryDeailActivity.lauch(mContext, bean);
            }
        });

        return convertView;
    }


    class ViewHolder {
        @Bind(R.id.danhao)
        TextView danhao;
        @Bind(R.id.zhuzhi)
        TextView zhuzhi;
        @Bind(R.id.mianji)
        TextView mianji;
        @Bind(R.id.details)
        TextView details;
        @Bind(R.id.baodan)
        Button baodan;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
